﻿@{
    ViewBag.Title = "SendCarRecord";
    ViewBag.First = "派车纪录";
    ViewBag.Second = "派车纪录列表";
    Layout = "~/Views/Shared/_BaseLayout.cshtml";

    var types = ViewData["type"] as IList<Sc.Domain.BaseItem>;
}
<link href="~/Content/css/select.css" rel="stylesheet" />
<script src="~/Content/laypage-v1.3/laypage/laypage.js"></script>
<script src="~/Content/laydate-v1.1/laydate/laydate.js"></script>
<script src="~/Scripts/select-ui.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".select2").uedSelect({
            width: 110
        });
        initDate("start", "end", "YYYY/MM/DD");
        loadData(1, 1);
    });
    //数据加载
    function loadData(curr, tag) {
        var url = '@Url.Action("GetSendCarRecordData")';
        var load = loadTip("数据加载中，请稍候", 16, 0);
        $.get(url, { pageSize: 10, pageIndex: curr, uName: $("#userName").val(), start: $("#start").val(), end: $("#end").val(), carNo: $("#carNo").val(), carType: $("#selType").val() }, function (data) {
            $("#listData").find("tr").remove();
            if (tag == 1) {
                initPage(data.PageCount, 1);
                $("#recordCount").html(data.RecordCount);
            }
            var table = document.getElementById("listData");
            $.each(data.Data, function (index, n) {
                var row = table.insertRow(table.rows.length);
                row.insertCell(0).innerHTML = (index + 1);
                row.insertCell(1).innerHTML = n.UserName;
                row.insertCell(2).innerHTML = n.Orgz;
                row.insertCell(3).innerHTML = n.StartAddress;
                row.insertCell(4).innerHTML = n.EndAddress;
                row.insertCell(5).innerHTML = ChangeDateFormat(n.StartTime);
                row.insertCell(6).innerHTML = n.TotalCount;
                row.insertCell(7).innerHTML = n.CarNo;
                row.insertCell(8).innerHTML = n.CarTypeName;
                row.insertCell(9).innerHTML = n.DriverName;
                row.insertCell(10).innerHTML = n.InstanceState == 4 ? "<a id='a_" + n.Id + "' href='javascript:backCar(" + n.Id + ")'>使用中</a>" : "已还车";
                row.insertCell(11).innerHTML = n.InstanceState == 4 ? "请还车" : "<a href='/CarInfo/ShowTrack?id=" + n.Id + "'>查看</a>";
                row.insertCell(12).innerHTML = "<a href='Paichedan?id=" + n.Id + "'>打印</a>";
            });
            $('.tablelist tbody tr:odd').addClass('odd');
            $("#currPage").html(curr);
            layer.close(load);
        });
    }
    //初始化分页
    function initPage(pageCount, curr) {
        laypage({
            cont: 'paginList',
            pages: pageCount,
            first: false,
            last: false,
            skip: true,
            curr: curr || 1,
            jump: function (e, first) {
                if (!first) {
                    loadData(e.curr)
                }
            }
        });
    }
    //导出
    function exportData() {
        window.location.href = '@Url.Action("ExportData")';
    }

    //还车
    function backCar(UseCarID) {
        if (confirm("确认结束本次行程，完成还车？")) {
            var url = '@Url.Action("SaveReturnCar")';
            var load = loadTip("还车数据处理中，请稍候", 16, 0);
            $.post(url, { bid: UseCarID }, function (data) {
                if (data == 1) {
                    alert("还车成功!");
                    $("#a_" + UseCarID).parent().html("已还车");
                } else {
                    alert("还车失败!请重试或联系管理员。");
                }
                layer.close(load);
            });
        }
    }
</script>
<div id="content" class="rightinfo">
    <div id="tab2" class="tabson">
        <ul class="seachform">
            <li>
                <label>用车人</label>
                <input type="text" class="scinput" style="width:80px" id="userName" />
            </li>
            <li>
                <label>车牌号</label>
                <input type="text" class="scinput" style="width:80px" id="carNo" />
            </li>
            <li>
                <label>车辆类型</label>
                <div class="vocation">
                    <select name="select" class="select2" id="selType">
                        <option value="">----请选择----</option>
                        @foreach (var item in types)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    </select>
                </div>
            </li>

            <li>
                <label>开始时间</label>
                <input type="text" id="start" style="width:80px" readonly="readonly" class="scinput" />
            </li>
            <li>
                <label>结束时间</label>
                <input type="text" id="end" style="width:80px" readonly="readonly" class="scinput" />
            </li>
            <li>
                <label>&nbsp;</label>
                <input type="button" class="scbtn" onclick="loadData(1, 1);" value="查询" />
            </li>
            <li>
                <label>&nbsp;</label>
                <input type="button" class="scbtn" onclick="exportData();" value="导出" />
            </li>
        </ul>
    </div>
    <table class="tablelist">
        <thead>
            <tr>
                <th width="40px">编号</th>
                <th>用车人</th>
                <th>所在部门</th>
                <th>起点</th>
                <th>终点</th>
                <th>用车时间</th>
                <th>人数</th>
                <th>所派车辆</th>
                <th>车辆类型</th>
                <th>驾驶员</th>
                <th>状态</th>
                <th>行驶轨迹</th>
                <th>派车单</th>
            </tr>
        </thead>
        <tbody id="listData"></tbody>
    </table>
    <div class="pagin">
        <div class="message" style="padding-top:5px;">共&nbsp;<i class="blue" id="recordCount"></i>&nbsp;条记录，当前显示第&nbsp;<i class="blue" id="currPage"></i>&nbsp;页</div>
        <ul class="paginList" id="paginList"></ul>
    </div>
</div>
